import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/Index.vue'
import Login from '../views/Login.vue'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'Index',
        component: Index,
        meta:{
            requireAuth:true
        },
        children: [
            {
                path:'/uploadVideo',
                name:'uploadVideo' ,
                component:()=>import('../components/upVideo.vue')
            },
            //系统首页
            {
                path: '/index',
                name: 'index',
                component: () => import('../components/index.vue')
            },
            // 提现设置
            {
                path: '/withdraw',
                name: 'withdraw',
                component: () => import('@/views/withdraw/withdraw-set')
            },
            //商品列表
            {
                path: '/userList',
                name: 'userList',
                component: () => import('@/views/userList/userList.vue')
            },
            {
                path: '/goodsList',
                name: 'goodsList',
                component: () => import('@/views/goodsAre/goodsList.vue')
            },
            {
                // path: '/newGoods/:type/:list',
                path: '/newGoods',
                name: 'newGoods',
                component: () => import('@/views/goodsAre/newGoods.vue')
            },
            //商品分类列表
            {
                path: '/classList',
                name: 'classList',
                component: () => import('../views/classAre/classList.vue')
            },
            {
                path: '/newClass',
                name: 'newClass',
                component: () => import('../views/classAre/newClass.vue')
            },
            {
                path: '/bannerList',
                name: 'bannerList',
                component: () => import('../views/bannerAre/bannerList.vue')
            },
            {
                path: '/newBanner',
                name: 'newBanner',
                component: () => import('../views/bannerAre/newBanner.vue')
            },
            //供货商
            {
                path:'/supplier',
                name:'supplier',
                component:() => import('../views/supplier/supplierList.vue')
            },
            {
                path:'/supplier_info',
                name:'supplierInfo',
                component:() => import('../views/supplier_base/supplierInfo.vue')
            },
            {
                path:'/supplier_reset_pwd',
                name:'supplierResetPwd',
                component:() => import('../views/supplier_base/supplierResetPwd.vue')
            },
            {
                path:'/newSupplier',
                name:'newSupplier',
                component:() => import('../views/supplier/newSupplier.vue')
            },
            //会员列表
            {
                path:'/memberList',
                name:'memberList',
                component:() => import('../views/member/memberList.vue')
            },
            {
                path:'/memberCheckList',
                name:'memberCheckList',
                component:() => import('../views/member/memberCheckList.vue')
            },
            {
                path:'/memberRule',
                name:'memberRule',
                component:() => import('../views/member/memberRule.vue')
            },
            //订单列表
            {
                path:'/supplier_order',
                name:'supplierOrder',
                component:()=> import('../views/supplierOrder/order.vue')
            },
            {
                path:'/redund_list',
                name:'redund_list',
                component:() => import('../views/supplierOrder/redund.vue')
            },
            {
                path:'/fx_self_order',
                name:'fx_self_order',
                component:()=> import('../views/fxOrder/fxOrder')
            },
            {
                path:'/supplier_order_detail',
                name:'supplierOrderDetail',
                component:()=> import('../views/supplierOrder/orderDetails.vue')
            },
            {
                path:'/income',
                name:'income',
                component:()=>import('../views/financial/incomeList.vue')
            },
            {
                path:'/fx_order_details',
                name:'fx_order_details',
                component:()=>import('../views/fxOrder/fxOrderDetail.vue')
            },
            //会员个人商品列表
            {
                path:"/fx_goods_list",
                name:"fx_goods_list",
                component:()=> import('../views/fxGoodsList/fxGoodsList.vue')
            },
            {
                path:'/fx_goods_details',
                name:'fx_goods_details',
                component:()=>import('../views/fxGoodsList/fxGoodsDetail.vue')
            },
            {
                path:'/ce',
                name:'ce',
                component:()=>import('../views/ceshi.vue')
            },
            {
                path:'/agreement',
                name:'agreement',
                component:() => import('../views/agreementList.vue')
            },
            {
                path:'/grossProfit',
                name:'grossProfit',
                component:() => import('../views/financial/grossProfit.vue')
            },
            {
                path: '/redund_details/:info',
                name:'redund_details',
                component:() => import('../views/supplierOrder/redundDetails.vue')
            },
            {
                path:'/productCensue',
                name:'productCensue',
                component:() => import('../views/financial/productCensue.vue')
            },
            {
                path:'/memberFinancial',
                name:'memberFinancial',
                component:() => import('../views/financial/memberFinancial.vue')
            },
            {
                path:'/shareData',
                name:'shareData',
                component:() => import('../views/dataPage/shareData.vue')
            },
            // 积分商品
            {
                path: '/integralProduct',
                name: 'integralProduct',
                component: () => import('../views/Integral/integral-product.vue')
            },
            // 积分规则
            {
                path: '/integralRules',
                name: 'integralRules',
                component: () => import('../views/Integral/integral-rules.vue')
            },
            // 积分订单
            {
                path: '/integralOrder',
                name: 'integralOrder',
                component: ( )=> import('@/views/Integral/integral-order.vue')
            },
            {
                path: '/integralOrderDetail',
                name: 'integralOrderDetail',
                component: () => import('@/views/Integral/components/order-detail.vue')
            }
        ]
    },
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (about.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
    // },
    {
        path: '/Login',
        name: 'Login',
        component: Login
    },
    {
        path:'/supplierApply',
        name:'supplierApply',
        component:()=>import('../views/supplierApply')
    }
]

const router = new VueRouter({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes
})


// 路由判断登录 根据路由配置文件的参数  全局守卫
router.beforeEach((to, from, next) => {
    if (to.matched.some(record => record.meta.requireAuth)){ // 判断该路由是否需要登录权限
        // console.log('需要登录');
        if (sessionStorage.code == 200) { // 判断当前的token是否存在 ； 登录存入的token
            next();
        }
        else {
            next({
                path: '/login'
            })
        }
    }
    else {
        // console.log('不需要登录');
        next();
    }
});

export default router
